e2a18c97be2c4a17c7cf2f86836cbc28656603b2,src/main/java/org/datanucleus/store/rdbms/sql/SelectStatement.java,SelectStatement,addOrderComponent,#SQLText#String#SQLExpression#boolean#NullOrderingType#DatastoreAdapter#,1113

Before Change



    protected void addOrderComponent(SQLText orderST, String orderString, SQLExpression orderExpr, boolean orderDirection, NullOrderingType orderNullDirective, DatastoreAdapter dba)
    {
        if (orderNullDirective != null && !dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_USING_ISNULL) && !dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_DIRECTIVES) &&
            !dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_USING_COLUMN_IS_NULL))
        {
            NucleusLogger.DATASTORE_RETRIEVE.warn("Query contains NULLS directive yet this datastore doesn't provide any support for handling this. Nulls directive will be ignored");
        }

        String orderParam = dba.getOrderString(rdbmsMgr, orderString, orderExpr);
        if (orderNullDirective == NullOrderingType.NULLS_LAST)
        {
            if (dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_USING_ISNULL) && orderExpr.getSQLTable() != null)
            {
                // Datastore requires nulls last using ISNULL extra ordering clause. Note : don't do this when the ordering component is not a simple column
                orderST.append("ISNULL(").append(orderParam).append("),");
            }
            else if (dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_USING_COLUMN_IS_NULL) && orderExpr.getSQLTable() != null)
            {
                // Datastore requires nulls last using "{col} IS NULL" extra ordering clause. Note : don't do this when the ordering component is not a simple column
                orderST.append(orderParam).append(" IS NULL,");

After Change


    protected void addOrderComponent(SQLText orderST, String orderString, SQLExpression orderExpr, boolean orderDirection, NullOrderingType orderNullDirective, DatastoreAdapter dba)
    {
        String orderParam = dba.getOrderString(rdbmsMgr, orderString, orderExpr);
        if (orderNullDirective != null)
        {
            if (dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_DIRECTIVES))
            {
                // Apply "NULLS [FIRST | LAST]" directly since supported by this datastore
                orderST.append(orderParam).append(orderDirection ? " DESC" : "");
                orderST.append(orderNullDirective == NullOrderingType.NULLS_FIRST ? " NULLS FIRST" : " NULLS LAST");
            }
            else if (dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_USING_CASE_NULL))
            {
                // "(CASE WHEN {param} IS NULL THEN 1 ELSE 0 END) [ASC|DESC], {param} [ASC|DESC]"
                orderST.append("(CASE WHEN " + orderParam + " IS NULL THEN 1 ELSE 0 END)").append(orderDirection ? " DESC" : " ASC");
                orderST.append(", " + orderParam).append(orderDirection ? " DESC" : " ASC");
            }
            else if (dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_USING_COLUMN_IS_NULL))
            {
                if (orderNullDirective == NullOrderingType.NULLS_LAST && orderExpr.getSQLTable() != null)
                {
                    // Datastore requires nulls last using "{col} IS NULL" extra ordering clause. Note : don't do this when the ordering component is not a simple column
                    orderST.append(orderParam).append(" IS NULL,");
                }
            }
            else if (dba.supportsOption(DatastoreAdapter.ORDERBY_NULLS_USING_ISNULL))
            {
                if (orderNullDirective == NullOrderingType.NULLS_LAST && orderExpr.getSQLTable() != null)
                {
                    // Datastore requires nulls last using ISNULL extra ordering clause. Note : don't do this when the ordering component is not a simple column
                    orderST.append("ISNULL(").append(orderParam).append("),");
                }
            }
            else
            {
                NucleusLogger.DATASTORE_RETRIEVE.warn("Query contains NULLS directive yet this datastore doesn't provide any support for handling this. Nulls directive will be ignored");
            }
        }
        else
        {
            orderST.append(orderParam).append(orderDirection ? " DESC" : "");
        }
    }